package com.jet.goods.remote.stock;

import com.jet.core.exception.CustomException;
import com.jet.core.result.ResultJson;
import com.jet.goods.remote.stock.dto.StockSpuDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author dcl
 * @since 2025/2/21 13:43
 */
@Service
@Slf4j
public class GoodsStockRemote {

    private final GoodsStockRemoteFeign goodsStockRemoteFeign;

    public GoodsStockRemote(GoodsStockRemoteFeign goodsStockRemoteFeign) {
        this.goodsStockRemoteFeign = goodsStockRemoteFeign;
    }

    public void asyncSpu(long merchantNo, StockSpuDto dto) {
        ResultJson<Void> result = goodsStockRemoteFeign.async(merchantNo, dto);
        if (result.getCode() != ResultJson.ok().getCode()) {
            log.error("同步商品信息异常，{}", result.getMsg());
            throw new CustomException(result.getMsg());
        }
    }

    public void asyncSpuStatus(long merchantNo, String spuId, int status) {
        ResultJson<Void> result = goodsStockRemoteFeign.asyncStatus(merchantNo, spuId, status);
        if (result.getCode() != ResultJson.ok().getCode()) {
            log.error("同步商品状态信息异常，{}", result.getMsg());
            throw new CustomException(result.getMsg());
        }
    }

    public void deleteBySpuId(long merchantNo, String spuId) {
        ResultJson<Void> result = goodsStockRemoteFeign.deleteBySpuId(merchantNo, spuId);
        if (result.getCode() != ResultJson.ok().getCode()) {
            log.error("删除商品信息异常，{}", result.getMsg());
            throw new CustomException(result.getMsg());
        }
    }

    public void deleteBySkuId(String skuId) {
        ResultJson<Void> result = goodsStockRemoteFeign.deleteBySkuId(skuId);
        if (result.getCode() != ResultJson.ok().getCode()) {
            log.error("删除商品信息异常，{}", result.getMsg());
            throw new CustomException(result.getMsg());
        }
    }
}
